package edu.depaul.se.courseregistration.sessionbean;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Group2
 */
@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class InitTableEJB  {

    @PersistenceContext(unitName="CourseRegistrationModulePU")
    private EntityManager em;
    
    public  void initDB(String[] stmt) {

        
          for (int i = 0; i < stmt.length; i++) {
          em.createNativeQuery(stmt[i]).executeUpdate();
       }
    }

    // delete all data in tables -> result: empty tables
    public  void clearDB(String[] stmt) {
        
        for (int i = 0; i < stmt.length; i++) {
            em.createNativeQuery(stmt[i]).executeUpdate();
        }
    }   
  
}
